package org.smartagents.body;

import org.smartagents.enviro.EnvironmentConstants;
import org.smartagents.util.Logger;

public class SubstanceFactory {

    public static Substance getSubstance(String substance) {
        //name , speciality&maxTick&triggercondition&E-A-C
        
        String[] details = substance.split(EnvironmentConstants.SUBSTANCE_DETAILS_SEPARATOR);

        Substance sub = new Substance();

        sub.setName(details[0]);
        sub.setMaxTick(Integer.valueOf(details[1]));
        sub.setLinkCondition(details[2]);
        if (details.length>3) {
            sub.setSpeciality(details[3].split(EnvironmentConstants.SUBSTANCE_SPECIALITY_SEPARATOR));
        } 

        return sub;
    }

    public static Substance getSubstance(String name, int maxTick, String linkCondition, String speciality) {
        Substance sub = new Substance();
        sub.setName(name);
        sub.setMaxTick(maxTick);
        sub.setLinkCondition(linkCondition);
        if (speciality==null) {
            speciality="";
        }
        sub.setSpeciality(speciality.split(","));

        return sub;
    }

   

    public static Substance getSubstance(String substance, int x, int y) {
        //name , speciality,maxTick,triggercondition, E|A|C
        String[] details = substance.split(EnvironmentConstants.SUBSTANCE_DETAILS_SEPARATOR);

        Substance sub = new Substance();

        sub.setName(details[0]);
        sub.setMaxTick(Integer.valueOf(details[1]));
        sub.setLinkCondition(details[2]);
        sub.setSpeciality(details[3].split(EnvironmentConstants.SUBSTANCE_SPECIALITY_SEPARATOR));
        sub.setX(x);
        sub.setY(y);

        return sub;
    }
}
